﻿#ifndef UPDATEPROGREMS_H
#define UPDATEPROGREMS_H

#include <QObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonParseError>
#include <QJsonValue>
#include <QMap>
#include <QProcess>


#include "../ymodoms/YmodemFileTransmit.h"
#include "../ymodoms/YmodemFileReceive.h"
#include "../ymodoms/Ymodem.h"

class UpdateProgrems : public QObject
{
    Q_OBJECT
public:
    explicit UpdateProgrems(QObject *parent = nullptr);
    virtual ~UpdateProgrems();

    void initUpdates();
    void clearDirectory(const QString &path);
    static UpdateProgrems * gestance();
    void saveFile(QByteArray infors);

    void transmitFile(QString paths);
    void receiveFile(QString paths);

    void receivePaths();


    void writeFlile(QString infos);
    bool  checkZipIntegrity(const QString &zipPath);

signals:

private slots:
    void onTransmitProgress(int progress);
    void onReceiveProgress(int progress);
    void onTransmitStatus(YmodemFileTransmit::Status status);
    void onReceiveStatus(YmodemFileReceive::Status status);

    void onMcuUpdateTimeout0();
    void onMcuUpdateTimeout1();


private:
    static UpdateProgrems  * m_updateProgrems;
    QString m_updatefiles;
    QString m_updatePahtsfiles;
    QString m_updateShellPahts;
    QString m_updateSourcePahts;

    YmodemFileTransmit *ymodemFileTransmit;
    YmodemFileReceive *ymodemFileReceive;

    bool transmitButtonStatus;
    bool receiveButtonStatus;

    // QProcess * m_cmdProcess;
    QTimer * m_mcuUpdateTimer0;
    QTimer * m_mcuUpdateTimer1;

};

#endif // UPDATEPROGREMS_H
